package com.jyniubi.gmall.cart.config;

import com.jyniubi.gmail.common.exception.AuthException;
import com.jyniubi.gmail.common.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.io.File;
import java.security.PrivateKey;
import java.security.PublicKey;

@ConfigurationProperties(prefix = "jwt")
@Slf4j
@Data
public class JwtProperties {
    private String pubKeyPath;
    private String userKey;
    private Integer expire;
    private String cookieName;
    private PublicKey publicKey;

    @PostConstruct
    public void init(){
        try {
            // 读取公私钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            log.error("初始化公钥失败！",e);
            throw new AuthException("初始化公钥失败！");
        }
    }
}
